package cate.game.stat.login;

import cate.game.framework.ModuleMan;
import cate.game.role.Role;
import cp.solution.business.stat.retention.dto.StatLoginEvent;
import cp.solution.business.sys.account.AccountEntity;
import cp.solution.rpc.path.RpcStatPath;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StatLoginHandler extends ModuleMan {

    @Override
    public void initDependent() throws Exception {

    }

    public void whenAccountLogin(AccountEntity account) {
        StatLoginEvent event = new StatLoginEvent();
        event.setAccountId(account.getId());
        event.setIp(account.getIp());
        event.setGameId(account.getGameId());
        event.setSrvId(game.config.srvId);
        event.setGroupCode(game.config.gs.getGroupCode());
        game.rpcSend().fireAndForgetStat(RpcStatPath.ROLE_LOGIN_EVENT, event);
    }

    public void whenRoleLogin(Role role) {
        StatLoginEvent event = new StatLoginEvent();
        event.setRoleId(role.getUid());
        event.setGameId(role.getBase().gameId);
        event.setSrvId(game.config.srvId);
        event.setGroupCode(game.config.gs.getGroupCode());
        game.rpcSend().fireAndForgetStat(RpcStatPath.ROLE_LOGIN_EVENT, event);
    }

}
